<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="js/vue.js" type="text/javascript" charset="utf-8"></script>
</head>

<body>
    <div id="app">
        <ul>
            <!-- 如果v-if和v-for同时作用在同一个元素的时候；
                vue3中v-if的优先级高于v-for
                vue2中v-for的优先级高于v-if
            -->
            <!-- 在渲染期间，属性todo确实被访问了，todo并没有定义在实例上 -->
            <!-- <li v-for="todo of todoList" :key='todo.id' v-if='!todo.completed'>
                {{todo.content}}
            </li> -->
            <!-- <template v-for="todo of todoList">
                <li  v-if='!todo.completed'>
                    {{todo.content}}
                </li>
            </template> -->
            <!-- 使用计算属性 -->
            <!-- <li v-for="todo of NotCompletedTodoList" :key='todo.id'>
                {{todo.content}}
            </li> -->
            <li v-for="todo of NotCompletedTodoList" :key='todo.id'>
                {{todo.content}}
            </li>
        </ul>
    </div>
    <script type="text/javascript">
        /**
         * v-if和v-for
         * 不推荐在同一元素上使用v-if和v-for
         * 
         **/
        var vm = new Vue({
            el: '#app',
            data() {
                return {
                    todoList: [{
                        id: 1,
                        content: 'content 1',
                        completed: false
                    }, {
                        id: 2,
                        content: 'content 2',
                        completed: true
                    }, {
                        id: 3,
                        content: 'content 3',
                        completed: false
                    }]
                }
            },
            computed: {
                NotCompletedTodoList() {
                    return this.todoList.filter(item => !item.completed)
                }
            },
            mounted() {

            },
            methods: {

            }
        })
    </script>
</body>

</html>